package cn.zyq.ykb.controller.tk;

import org.springframework.security.access.prepost.PreAuthorize;
import cn.zyq.ykb.system.ry.util.poi.ExcelUtil;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.annotation.Log;
import cn.zyq.ykb.system.ry.enums.BusinessType;
import cn.zyq.ykb.beans.tk.Menu;
import cn.zyq.ykb.service.tk.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.common.PageParam;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 菜单Controller
 *
 * @author SystemAuth
 * @date 2023-10-20
 */

@RestController(value = "MgtMenuController")
@RequestMapping("/api/menu")
@Api(tags = "菜单接口")
public class MenuController extends BaseController {

    @Autowired
    private MenuService menuService;

    /**
     * 查询菜单列表
     */
    @ApiOperation(value = "列表", response = Menu.class)
    @PostMapping("/list")
    public Object list(@RequestBody PageParam pageParam) {
        return this.menuService.selectMenuList(pageParam);
    }

    /**
     * 获取菜单详细信息
     */
    @ApiOperation(value = "详情", response = Menu.class)
    @GetMapping(value = "/{menuID}/{tUserID}")
    public Object getInfo(@PathVariable("menuID") Integer menuID,@PathVariable("tUserID") Integer tUserID) {
        return this.menuService.selectMenuByMenuID(menuID,tUserID);
    }
    /**
     * 获取菜单详细信息
     */
    @ApiOperation(value = "详情", response = Menu.class)
    @GetMapping(value = "/detail/{serviceID}")
    public Object getInfo(@PathVariable(value = "serviceID") String serviceID) {
        return this.menuService.selectMenuByServiceID(serviceID);
    }

    /**
     * 新增菜单
     */
    @ApiOperation(value = "新增")
    @Log(title = "菜单", businessType = BusinessType.INSERT)
    @PostMapping
    public Object add(@RequestBody Menu menu) {
        return this.menuService.insertMenu(menu);
    }

    /**
     * 修改菜单
     */
    @ApiOperation(value = "编辑")
    @Log(title = "菜单", businessType = BusinessType.UPDATE)
    @PutMapping
    public Object edit(@RequestBody Menu menu) {
        return this.menuService.updateMenu(menu);
    }

    /**
     * 删除菜单
     */
    @ApiOperation(value = "删除")
    @Log(title = "菜单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{menuIDs}")
    public Object remove(@PathVariable Integer[] menuIDs) {
        return this.menuService.deleteMenuByMenuIDs(menuIDs);
    }
}
